﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Pibby.Core.Tests
{
	[TestClass]
	public class DownloadableTests
	{
		[TestMethod]
		public void NeedsOnlyLinkAndTargetFolder()
		{
			string link = "http://www.downloadfromhere.com/myfile.mp3";
			string folder = "C:\\Downloads";

			Downloadable file = new Downloadable(new Uri(link), folder);

			Assert.AreEqual(link, file.Uri.AbsoluteUri, "Link not correct");
			Assert.AreEqual(folder, file.TargetFolder, "Folder not correct");
			Assert.AreEqual(System.IO.Path.Combine(folder, "myfile.mp3"), file.LocalPath, "Local path not correct");
		}

		[TestMethod]
		public void FriendlyNameDefaultsToFileName()
		{
			string link = "http://www.downloadfromhere.com/myfile.mp3";

			Downloadable file = new Downloadable(new Uri(link));

			Assert.AreEqual("myfile.mp3", file.FriendlyName, "Friendly name not correct");
		}

		[TestMethod]
		public void ChangingTargetFolderChangesLocalPath()
		{
			string link = "http://www.downloadfromhere.com/myfile.mp3";
			string folder = "C:\\Downloads";

			Downloadable file = new Downloadable(new Uri(link), folder);
			Assert.AreEqual(link, file.Uri.AbsoluteUri, "Link not correct");
			Assert.AreEqual(folder, file.TargetFolder, "Folder not correct");

			string newFolder = "C:\\My Music";
			file.TargetFolder = newFolder;

			Assert.AreEqual(newFolder, file.TargetFolder, "Folder did not change correctly");
			Assert.AreEqual(System.IO.Path.Combine(newFolder, "myfile.mp3"), file.LocalPath, "Local path did not change correctly");
		}
	}
}
